<template>
  <div class="logmian" v-if="logList.length" v-infinite-scroll="load">
    <div class="title">操作记录</div>
    <div class="changedby" v-for="(item, index) in logList" :key="index">
      <div class="changedby_left"></div>
      <div class="changedby_main">
        <div class="name">{{dateFormat(item.opat)}} {{item.changedbyname}} {{ typeName(item.changedbytype) }}</div>
        <div class="message">{{item.changelogmessage}}</div>
      </div>
    </div>
  </div>
</template>
<script>
import { getParentChangeLog } from "@/api/mubao";
import { formatDate } from "@/utils/validate";
export default {
  props: ["id"],
  data() {
    return {
      loading:false,
      page: 1,
      pageSize: 10,
      parentPackageId: 0,
      total:0,
      logList: []
    };
  },
  created() {
    this.parentPackageId = this.id;
    this.getParentChangeLog();
  },
  computed: {
    dateFormat(){
      return function(date){
        if(date){
          return formatDate(new Date(date),'yyyy-MM-dd HH:mm')
        }
      }
    },
    typeName(){
      return function(type){
        let name = "";
        switch(type){
          case 1:
            name = "推广商"
          break;
          case 2:
            name = "推广员"
          break;
          case 3:
            name = "代理商"
          break;
          case 4:
            name = "子账号"
          break;
        }
        return name;
      }
    }
  },
  methods: {
    getParentChangeLog() {
      let data = {
        page: this.page,
        pageSize: this.pageSize,
        parentPackageId: this.parentPackageId
      };
      if(this.loading){
        return;
      }
      this.loading = true;
      getParentChangeLog(data).then(res => {
        this.loading = false;
        if (res.code === 0) {
          this.total = res.data.total;
          if(this.total/this.pageSize > this.page){
            this.page++;
          }else{
            this.loading = true;
          }
          this.logList = res.data.values ? this.logList.concat(res.data.values):[];
        } else {
          this.page--;
          this.$message.error(res.message);
        }
      });
    },
    load () {
      this.getParentChangeLog();
    }
  }
};
</script>
<style lang="scss">
.logmian{
    background: #ffffff;
    box-shadow: 0 0 6px 0 rgba(0, 21, 41, 0.09);
    border-radius: 4px;
    padding: 28px 32px 18px 32px;
    margin: 0 0 16px 0;
    margin-top: 21px;
    .title{
      font-size: 16px;
      color: #404040;
      margin-bottom: 28px;
      font-weight: bold;
    }
    .changedby{
      position: relative;
      padding: 0 12px 10px 12px;
      font-size: 14px;
      color: #0D0D0D;
      line-height: 26px;
      &::before{
        display: block;
        content: ' ';
        height: calc(100% - 5px);
        position: absolute;
        left: 0;
        top: 13px;
        width: 1px;
        background: #ccc;
      }
      &:last-child::before{
        display: none;
      }
      .changedby_left{
        position: absolute;
        left: -5px;
        top: 8px;
        background: #fff;
        border:2px solid #a80100;
        width: 10px;
        height: 10px;
        border-radius: 5px;
      }
      .message{
        color: #777;
      }
    }
}
</style>
